package com.lx.test;

public class quicksortdemo {
    public static void main(String[] args) {
        int arr[] = {6,1,2,7,9,3,4,5,10,8};
        sort(arr,0,arr.length-1);
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
//        quicksort(arr,0,arr.length-1);
    }


    private static void sort(int[] arr, int left, int right) {
        int temp = arr[left];
        int i = left;
        int j = right;
        if(left>=right)
        {
            return ;
        }
        while(left<right)
        {
            while(arr[right]>=temp&&left<right)
            {
                right--;
            }
            while(arr[left]<=temp&&left<right)
            {
                left++;
            }
            int number = arr[left];
            arr[left] = arr[right];
            arr[right] = number;
        }
        arr[i] = arr[left];
        arr[left] = temp;
        sort(arr,i,left-1);
        sort(arr,left+1,j);
    }
}
